package com.giga.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.giga.injectors.MySqlInjector;
import com.giga.plugins.MyInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyBatisPlusConfig {
    @Bean
    public MybatisPlusInterceptor paginationInterceptor(){
        MybatisPlusInterceptor interceptor=new MybatisPlusInterceptor();
        //配置分页插件
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        //配置防止全表更新与删除插件(sql分析插件)
        interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
        //配置乐观锁
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        return interceptor;
    }
//    @Bean   //Oracle的序列生成器
//    public OracleKeyGenerator oracleKeyGenerator(){
//        return new OracleKeyGenerator();
//    }
    @Bean   //注入自定义的拦截器
    public MyInterceptor myInterceptor(){
        return new MyInterceptor();
    }

    @Bean   //注入自定义的SQL注入器
    public MySqlInjector mySqlInjector(){
        return new MySqlInjector();
    }
}
